<template>
  <!-- 修改密码/重置密码 -->
  <view class="wjmm">
    <view class="wjmmmodal">
      <view class="wjmmphone" style="margin-top: 15rpx;">
        <u-input placeholder="请输入手机号" border="bottom" clearable v-model="wjmmphone"></u-input>
      </view>
      <view class="wjmmyzm">
        <view class="u-demo-block__content" style="margin-top: 15rpx;">
          <!-- #ifndef APP-NVUE -->
          <u-input placeholder="请输入验证码" v-model="wjmmcode" border="bottom">
            <template slot="suffix">
              <u-code
                ref="uCode"
                @change="codeChange"
                seconds="60"
                changeText="X秒后重新获取"
              ></u-code>
              <u-button
                @tap="wjmmgetCode"
                :text="tips"
                type="success"
                size="mini"
                style="margin-left: 10rpx;"
              ></u-button>
            </template>
          </u-input>
          <!-- #endif -->
          <!-- #ifdef APP-NVUE -->
          <u-input v-model="wjmmcode" border="bottom"></u-input>
          <!-- #endif -->
        </view>
      </view>
      <u-input placeholder="请输入新密码" border="bottom" clearable v-model="wjmmpassword" style="margin-top: 15rpx;"></u-input>
      <view class="wjmm-login">
        <u-button type="primary" text="重置" @click="czmm"></u-button>
      </view>
    </view>
  </view>
</template>

<script>
import { http } from "../static/service/requestAddress/rtas.js";
import { socketurl } from "../static/service/requestAddress/rtas.js";
const app = getApp();

export default {
  data() {
    return {
      wjmmphone: "",
      wjmmcode: "",
      wjmmpassword: "",
      tips: "",
    };
  },
  methods: {
    codeChange(text) {
      this.tips = text;
    },
    wjmmgetCode() {
      let str = /^((13[0-9])|(14[0-9])|(15[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\d{8}$/;
      if (str.test(this.wjmmphone)) {
        var msg = "";
        if (this.$refs.uCode.canGetCode) {
          uni.showLoading({
            title: "正在获取验证码",
          });
          uni.request({
            url: http + "user/resetcode/" + this.wjmmphone,
            method: "GET",
            complete: (res) => {
              msg = res.data.msg;
              if (res.data.code == 20021) {
                setTimeout(() => {
                  uni.hideLoading();
                  uni.$u.toast(msg);
                  this.$refs.uCode.start();
                }, 100);
              } else {
                uni.$u.toast(msg);
              }
            },
          });
        } else {
          uni.$u.toast("倒计时结束后再重试");
        }
      } else {
        uni.$u.toast("手机号格式有问题!");
      }
    },
    czmm() {
      console.log("重置密码" + this.wjmmphone + "|" + this.wjmmcode + "|" + this.wjmmpassword);
      uni.request({
        url: http + "user/resetpossword/" + this.wjmmphone + "/" + this.wjmmcode + "/" + this.wjmmpassword,
        method: "PUT",
        complete: (res) => {
          if (res.data.code == 20041) {
            uni.$u.toast("重置密码成功，快去登录吧!");
            setTimeout(() => {
              uni.switchTab({
                url: "/pages/massage/user",
              });
            }, 1000);
          } else {
            uni.$u.toast("重置密码失败!");
          }
        },
      });
    },
  },
};
</script>

<style>
  .wjmm {
    margin: 20px;
  }

  .wjmmmodal {
    height: 400px;
  }
  .wjmmphone,
    .wjmmyzm{
      margin-bottom: 15rpx;
    }
	.wjmm-login{
		margin-top: 50rpx;
	}
</style>
